package com.campus.util;

import java.io.File;
import java.text.DecimalFormat;

public abstract class FileUtil {

	public static String GetFileSize(File file){
	    String size = ""; 
	    if(file.exists() && file.isFile()){
	    long fileS = file.length();
	      DecimalFormat df = new DecimalFormat("#.00"); 
	           if (fileS < 1024) {
	               size = df.format((double) fileS) + "BT";
	           } else if (fileS < 1048576) {
	               size = df.format((double) fileS / 1024) + "KB";
	           } else if (fileS < 1073741824) {
	               size = df.format((double) fileS / 1048576) + "MB";
	           } else {
	               size = df.format((double) fileS / 1073741824) +"GB";
	           }
	    }else if(file.exists() && file.isDirectory()){
	    size = "";
	    }else{
	    size = "0BT";
	    }
	    return size;
	   }
	
	public static String GetFileType(File file){
	    String fileName=file.getName();    
	    String fileTyle=fileName.substring(fileName.lastIndexOf("."),fileName.length()); 
		return fileTyle;
		
	}
	
		
}
